home *** CD-ROM | disk | FTP | other *** search
- /*
- SNEWS 2.0
-
- active.c - routines to manipulate the active and ng files
-
-
- Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
- john@ahuriri.gen.nz
- PO Box 2708, Christchurch, NEW ZEALAND
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 1, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the file COPYING, which contains a copy of the GNU General
- Public License.
-
- Atari Version maintained by Graham Judd - gjudd@siward.demon.co.uk
- */
-
- /*---------------------------- Source Control ------------------------------*/
-
- /* $Id: ACTIVE.C,v 1.2 1994/02/05 18:46:56 gbj Exp user $
-
- /****************************************************************************
- * 20 May 92 1.2 GT ka9q configuration. *
- * 06 Jun 92 1.3 GT Invalidate freed pointers. *
- * 07 Jun 92 1.4 GT Fix mailqueue parameter. *
- * 12 Jun 92 1.5 NJL Configurable quote marks & Bios video parm. *
- * Ensure strtok() accepts tab as well as space. *
- * 15 Jun 92 1.6 GT Print name of file in error message. *
- * 17 Jul 92 1.7 GT C++ compilation. *
- * Heap debugging. *
- * "junk" flag. *
- * 16 Aug 92 1.8 MSM Snews 1.90 *
- * Mail_dir added for 1.90 thread / item saving *
- * Pseudo mail ID's added for article post / save *
- * 10 Oct 92 1.9 MSM Correct assumption that news == snews *
- * 13 Feb 93 1.10 MSM Add local posting option *
- * 20 Feb 93 1.11 MSM Local Posting read option *
- * 31 May 93 1.12 MSM Snews 2.0 *
- * temp_dir changed to be path only *
- * ng made optional *
- * 18 Jun 93 1.13 MSM Heap debugging removed (using Bounds Check) *
- * 3 Jul 93 1.14 MSM New UUCP items added for mail/editor *
- * 1 Aug 93 1.15 MSM Confirm Snews exit to DOS *
- * 11 Sep 93 1.16 MSM Null extracts string corrected *
- * 25 Nov 93 1.17 MSM Correct read list processing *
- * 4 Dec 93 1.18 MSM Allow blank organisation and remove from reqd. *
- * 2 Apr 94 1.19 MSM Colour processing now ignores incomplete lines *
- * Footer support *
- * Suspend support *
- ****************************************************************************/
-
- #include <ctype.h>
- #include <fcntl.h>
- #include <io.h>
- #include "defs.h"
- #include "active.h"
- #include "screen.h"
- #include "locking.h"
-
- #ifdef ATARI
- # include "st.h"
- # include "fileops.h"
- #endif
-
- #ifndef __TURBOC__
- # ifndef ATARI
- enum COLORS {
- BLACK, /* dark colors */
- BLUE,
- GREEN,
- CYAN,
- RED,
- MAGENTA,
- BROWN,
- LIGHTGRAY,
- DARKGRAY, /* light colors */
- LIGHTBLUE,
- LIGHTGREEN,
- LIGHTCYAN,
- LIGHTRED,
- LIGHTMAGENTA,
- YELLOW,
- WHITE
- };
- # endif
- #endif
-
- int headf = BLACK;
- int headb = LIGHTGRAY;
-
- int textf = LIGHTGRAY;
- int textb = BLACK;
-
- int helpf = LIGHTGRAY;
- int helpb = BLACK;
-
- int msgf = BLACK;
- int msgb = LIGHTGRAY;
-
-
- /*
- * These private variables are used to do all the i/o on the active
- * file.
- */
-
- static FILE *active_file;
- static ACTIVE *local_head;
- static POST_GROUPS *pg;
-
- /*-------------------------- load the active file --------------------------*/
-
- ACTIVE *load_active_file(void)
- {
-
- /*
- * This routine opens the active file.
- * It reads the data, allocating ACTIVE elements in a linked list.
- * Returns a pointer to the head of the linked list.
- */
-
- char fn[80], buf[81];
- char *p;
- ACTIVE *this_act, *head = NULL;
- long posn = 0;
- int ct = 0;
- int ct_gp = 0;
-
- /* open the file */
- strcpy(fn, my_stuff.news_dir);
- strcat(fn, "active");
- if ((active_file = fopen(fn, "r+b")) == NULL) {
- fprintf(stderr, "cannot open %s\n", fn);
- exit(1);
- }
- /* read and store */
- while (fgets(buf, 80, active_file) != NULL) {
-
- /* exit on ^Z on column 1 */
- if (buf[0] == '\x1A')
- break;
-
- ct++;
-
- if (strlen(buf) > 0) {
-
- if (head == NULL) {
- head = this_act = (ACTIVE *) malloc(sizeof(ACTIVE));
- head->last = NULL;
- head->index = ct_gp;
- head->suspend = FALSE;
- }
- else {
- ct_gp++;
- this_act->next = (ACTIVE *) malloc(sizeof(ACTIVE));
- this_act->next->last = this_act;
- this_act = this_act->next;
- this_act->index = ct_gp;
- this_act->suspend = FALSE;
- }
-
- if ((this_act) == NULL) {
- fprintf(stderr, "cannot allocate memory for active list\n");
- exit(1);
- }
- if ((p = strtok(buf, " \t")) == NULL) {
- fprintf(stderr, "active file corrupt at line %d\n", ct);
- exit(1);
- }
- strcpy(this_act->group, p);
-
- if ((p = strtok(NULL, " \t")) == NULL) {
- fprintf(stderr, "active file corrupt at line %d\n", ct);
- exit(1);
- }
- strcpy(this_act->gp_file, p);
-
- if ((p = strtok(NULL, " \t")) == NULL) {
- fprintf(stderr, "active file corrupt at line %d\n", ct);
- exit(1);
- }
- this_act->lo_num = atol(p);
-
- if ((p = strtok(NULL, " \t")) == NULL) {
- fprintf(stderr, "active file corrupt at line %d\n", ct);
- exit(1);
- }
- this_act->hi_num = atol(p);
-
- this_act->num_pos = posn;
- this_act->read_list = NULL;
- }
- posn = ftell(active_file);
- }
-
- this_act->next = NULL;
- head->groups = ct; /* added for 2.0 */
-
- local_head = head;
-
- /* load up the posting list */
- pg = post_group_file();
-
- return (head);
- }
-
-
- /*---------- free the active list and close the active file ----------------*/
- void close_active_file(void)
- {
-
- /*
- * Close the active file and deallocate the linked list
- */
-
- ACTIVE *this_act;
-
- this_act = local_head;
-
- while (this_act != NULL) {
- local_head = this_act;
- this_act = this_act->next;
- free(local_head);
- local_head = NULL;
- }
-
- fclose(active_file);
-
- free_ng();
-
- }
-
-
- /*------------------------- close the active file ---------------------------*/
- void close_active(void)
- {
-
- /*
- * Close the active file
- */
-
-
- fclose(active_file);
-
- }
-
-
- /*--------------------------- load the newsgroups file --------------------------*/
- POST_GROUPS *post_group_file(void)
- {
-
- /*
- * This routine opens the active file.
- * It reads the data, allocating POST_GROUPS elements in a linked list.
- * Returns a pointer to the head of the linked list.
- */
-
- char fn[80], buf[81], *p;
- POST_GROUPS *this_group = NULL, *head = NULL;
- int ct = 0;
- FILE *ngf;
-
- /* open the file - if none, return null */
- strcpy(fn, my_stuff.news_dir);
- strcat(fn, "ng");
- if ((ngf = fopen(fn, "rb")) == NULL) {
- return (NULL);
- }
-
- /* read and store */
- while (fgets(buf, 80, ngf) != NULL) {
-
- /* exit on ^Z on column 1 */
- if (buf[0] == '\x1A')
- break;
-
- ct++;
-
- if (strlen(buf) > 0) {
-
- if (head == NULL) {
- head = this_group = (POST_GROUPS *) malloc(sizeof(POST_GROUPS));
- }
- else {
- this_group->next = (POST_GROUPS *) malloc(sizeof(POST_GROUPS));
- this_group = this_group->next;
- }
-
- if ((this_group) == NULL) {
- fprintf(stderr, "cannot allocate memory for newsgroup list\n");
- exit(1);
- }
-
- if ((p = strtok(buf, " \n\r\t")) == NULL) {
- fprintf(stderr, "newsgroup 'ng' file corrupt at line %d\n", ct);
- exit(1);
- }
-
- strcpy(this_group->group, p);
- }
- }
-
- if (this_group) /* added in 2.0 */
- this_group->next = NULL;
-
- fclose(ngf);
-
- return (head);
- }
-
- /*-------------------- free the post groups structure ----------------------*/
- void free_ng()
- {
-
- /*
- * deallocate the post_groups linked list
- */
-
- POST_GROUPS *this_group;
-
- this_group = pg;
-
- while (this_group != NULL) {
- pg = this_group;
- this_group = this_group->next;
- free(pg);
- pg = NULL;
- }
- }
-
- /*------------------------- check group in post list -------------------------*/
- int check_valid_post_group(char *ng)
- {
-
- /*
- * Check a string as a valid newsgroup name. Returns TRUE if found
- */
-
- POST_GROUPS *this_group;
-
- if (pg == NULL)
- return (TRUE); /* no ng file, so default allow */
-
- this_group = pg;
-
- while (this_group != NULL) {
- if (strcmp(ng, this_group->group) == 0)
- return (TRUE);
- this_group = this_group->next;
- }
-
- return (FALSE);
- }
-
- int is_local_group(char *ng)
- { /* added for 2.0 */
- POST_GROUPS *this_group;
-
- this_group = pg;
-
- while (this_group != NULL) {
- if (strcmp(ng, this_group->group) == 0)
- return (this_group->local);
- this_group = this_group->next;
- }
- return (TRUE);
- }
-
-
- /*-------------------- find a newsgroup in active list ----------------------*/
- ACTIVE *find_news_group(char *group, int *junk_flag)
- {
-
- /*
- * This routine searches the active structure for the specified newsgroup,
- * and returns a pointer to the entry, or to group junk if not found.
- * The search for junk is made via a recursive call.
- * Fatal if junk not found
- */
-
- ACTIVE *this_act;
- #ifdef ATARI
- int done;
- #endif
-
- this_act = local_head;
-
- #ifdef ATARI
- done=FALSE;
- while (!done)
- {
- if (this_act != NULL)
- if (stricmp(group, this_act->group) != 0)
- {
- done=FALSE;
- this_act=this_act->next;
- }
- else
- done=TRUE;
- else
- done=TRUE;
- }
- #else
- while ((this_act != NULL) && (stricmp(group, this_act->group) != 0)) {
- this_act = this_act->next;
- }
- #endif
-
- *junk_flag = 0;
- if (this_act == NULL) {
- if (stricmp(group, "junk") != 0) {
- this_act = find_news_group("junk", junk_flag);
- *junk_flag = 1;
- }
- else {
- fprintf(stderr, "active file must have newsgroup junk\n");
- exit(1);
- }
- }
- return (this_act);
-
- }
-
-
- /*-------------------------- update active file ---------------------------*/
- void update_active_entry(ACTIVE * a)
- {
-
- /*
- * This routine takes a pointer to an active entry and updates its data
- * on disk
- */
-
- char buf[(ACTIVE_NUM_LEN * 2) + 2];
- int n;
- long where;
-
- sprintf(buf, "%08ld %08ld", a->lo_num, a->hi_num);
-
- n = (ACTIVE_NUM_LEN * 2) + 1;
- where = a->num_pos + strlen(a->group) + 1 + strlen(a->gp_file) + 1;
- fseek(active_file, where, SEEK_SET);
- if (fwrite(buf, 1, n, active_file) != (unsigned)n) {
- fprintf(stderr, "active file update failed for %s\n", a->group);
- exit(1);
- }
- fflush(active_file);
- }
-
- /*------------------- make newsgroup name and directory --------------------*/
- char *make_news_group_name(char *ng)
- {
-
- /*
- * This routine takes the newsgroup name, replaces the '.' with '\'
- * and creates the directory if none exists. The returned name
- * has a trailing '\'.
- * It doesn't do this for the DOS/ATARI version!
- */
-
- static char fn[80]; /* was 512 DOS name is 64 max */
- ACTIVE *tmp;
- int junk_flag;
-
- tmp = find_news_group(ng, &junk_flag);
-
- sprintf(fn, "%snewsbase\\%s", my_stuff.news_dir, tmp->gp_file);
-
- return (&fn[0]);
- }
-
-
- /*-------------------------- load the seen list -------------------------*/
- void load_read_list(void)
- {
-
- /*
- * Load the user's list of seen articles
- */
-
- FILE *tmp_file;
- ACTIVE *act;
- int i, continue_flag;
- int articles;
- char *a, buf[256], *p, real_name[80];
- int junk_flag;
-
- /* allocate the arrays and set to unread, ie FALSE */
- act = local_head;
- while (act != NULL) {
-
- articles = (int) (act->hi_num - act->lo_num);
- if (articles > 0) {
- a = act->read_list = (char *) malloc(articles * sizeof(char));
- for (i = 0; i < articles; i++) {
- *(a + i) = FALSE;
- }
- }
- else {
- act->read_list = NULL;
- }
- act = act->next;
- }
-
- /* read and process the file - if not present, just carry on */
-
- strcpy(buf, my_stuff.news_dir);
- strcat(buf, my_stuff.user);
- strcat(buf, ".nrc");
- if ((tmp_file = fopen(buf, "rt")) != NULL) {
-
- continue_flag = FALSE;
- while (fgets(buf, 255, tmp_file) != NULL) {
-
- p = strtok(buf, " \t\n\r");
-
- if (!continue_flag) {
-
- strcpy(real_name, p);
- act = find_news_group(p, &junk_flag);
- articles = (int) (act->hi_num - act->lo_num);
-
- /* if no articles or unknown group eat the rest */
-
- p = strtok(NULL, " \t\n\r");
-
- }
-
- /* scan the rest of the line getting numbers and setting flags */
-
- continue_flag = FALSE;
- while (p != NULL) {
-
- /* check for continuation backslash */
-
- if (*p != '\\') {
- i = (int) (atol(p) - (act->lo_num + 1));
- if ((i >= 0) && (i < articles) &&
- ((stricmp(act->group, "junk") != 0) ||
- (stricmp(real_name, "junk") == 0))) {
- *((act->read_list) + i) = (char) TRUE;
- }
- }
- else {
- continue_flag = TRUE;
- break;
- }
- p = strtok(NULL, " \t\n\r");
- }
- }
-
- fclose(tmp_file);
- }
- }
-
- /*-------------------------- save the seen list -------------------------*/
- void save_read_list(void)
- {
-
- /*
- * Save the user's list of read articles and deallocate storage
- */
-
-
- FILE *tmp_file;
- ACTIVE *act;
- int i, articles, ct;
- char buf[256];
-
- /* open the file */
- strcpy(buf, my_stuff.news_dir);
- strcat(buf, my_stuff.user);
- strcat(buf, ".nrc");
- if ((tmp_file = fopen(buf, "wt")) == NULL) {
- fprintf(stderr, "can't open user's rc file \"%s\" for output\n", buf);
- exit(1);
- }
-
- /* write out the lists and deallocate the arrays */
-
- act = local_head;
- while (act != NULL) {
-
- articles = (int) (act->hi_num - act->lo_num);
- if (articles > 0) {
- fprintf(tmp_file, "%s ", act->group);
-
- ct = 0;
-
- for (i = 0; i < articles; i++) {
- if (*((act->read_list) + i)) {
- ct++;
- fprintf(tmp_file, "%d ", i + act->lo_num + 1);
- if ((ct % 10) == 0)
- fprintf(tmp_file, "\\ \n");
- }
- }
-
- fprintf(tmp_file, "\n");
- if (act->read_list != NULL) {
- free(act->read_list);
- act->read_list = NULL;
- }
- }
- act = act->next;
- }
-
- fclose(tmp_file);
-
- }
-
- /*------------------------- set colors -----------------------------------*/
-
- void set_colors(char *keyword, char *value)
- {
- static char *colors[] = {"bla", "blu", "gre", "cya", "red", "mag", "yel", "whi"};
- int color = 0, i = 0;
- char *f = NULL;
-
- if (value)
- strlwr(value);
-
- f = strtok(value, "\0");
-
- while (isspace(*f))
- f++;
-
- for (i = 0; (i < 8) && (strncmp(colors[i], f, 3) != 0); i++)
- /* empty loop */ ;
-
- color = (i < 8) ? i : 0;
- color |= (strchr(f, '+') != NULL) ? 8 : 0;
-
- helpf = (strncmp("helpf", keyword, 5)) ? helpf : (unsigned char) color;
- helpb = (strncmp("helpb", keyword, 5)) ? helpb : (unsigned char) color;
-
- textf = (strncmp("textf", keyword, 5)) ? textf : (unsigned char) color;
- textb = (strncmp("textb", keyword, 5)) ? textb : (unsigned char) color;
-
- headf = (strncmp("headf", keyword, 5)) ? headf : (unsigned char) color;
- headb = (strncmp("headb", keyword, 5)) ? headb : (unsigned char) color;
-
- msgf = (strncmp("msgf", keyword, 4)) ? msgf : (unsigned char) color;
- msgb = (strncmp("msgb", keyword, 4)) ? msgb : (unsigned char) color;
- }
-
- /*------------------------- load UUPC rc files ---------------------------*/
- int load_stuff(void)
- {
-
- /*
- * Trawl the UUPC files to get the stuff we need
- * - return TRUE if completed ok
- */
-
- int i, res = 0;
- char buf[256], buf2[80];
- char *fn, *p, *v, *q;
- FILE *tmp;
-
- /* news base directory */
-
- if ((fn = getenv("SNEWS")) == NULL) {
- (void) fprintf(stderr, "SNEWS environment variable undefined\n");
- exit(1);
- }
-
- /* give it a trailing \ */
-
- (void) strcpy(my_stuff.news_dir, fn);
- if (my_stuff.news_dir[strlen(my_stuff.news_dir) - 1] != '\\')
- (void) strcat(my_stuff.news_dir, "\\");
-
- /* Set up default items where appropriate */
-
- (void) strcpy(my_stuff.quotemark, ">");
- my_stuff.directvideo = 1; /* default to direct video */
- my_stuff.localpost = 0; /* default to posting via demon */
- my_stuff.localread = 0; /* default to reading local posts */
- my_stuff.exitconfirm = 1; /* default, don't ask */
- my_stuff.expert = FALSE; /* default to non expert */
- strcpy(my_stuff.replyuser, ""); /* default no replyto name */
- strcpy(my_stuff.mailuser, "newspost");/* default posting log */
- strcpy(my_stuff.maillog, "outmail"); /* default mail log */
- strcpy(my_stuff.extruser, "snewsex"); /* default extract file */
- strcpy(my_stuff.my_organisation, ""); /* default organisation */
- strcpy(my_stuff.mail_id, "mail2news");/* default mail to news ID */
- strcpy(my_stuff.edit_line, ""); /* default editor command */
- strcpy(my_stuff.alias_file, ""); /* default alias file */
- my_stuff.tab_action = TRUE; /* New tab action by default */
- my_stuff.header_quote = FALSE; /* No header quotes by default */
- my_stuff.footer_quote = TRUE; /* Footer quotes on by default */
- my_stuff.show_unread = TRUE; /* Show unread threads etc. */
- my_stuff.match_len = 15; /* Length of header minimum match */
-
- /* read the system file first */
-
- (void) strcpy(buf, my_stuff.news_dir);
- (void) strcat(buf, "snews.rc");
- if ((tmp = fopen(buf, "rt")) != NULL) {
- while (fgets(buf, 255, tmp)) {
- p = strtok(buf, " \t=\r\n");
- if (p != NULL) {
- if (*p != '#') {
- v = strtok(NULL, " \t=\r\n");
- if ((stricmp(p, "newsserver") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.mail_server, v);
- res++;
- }
-
- if ((stricmp(p, "colour") == 0) && (v != NULL)) {
- p = strtok(NULL, " \r\n");
- set_colors(v, p);
- }
-
- if ((stricmp(p, "nodename") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.my_site, v);
- res++;
- }
-
- if ((stricmp(p, "newsdir") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.incoming_dir, v);
- if (my_stuff.incoming_dir[strlen(my_stuff.incoming_dir) - 1] != '\\')
- (void) strcat(my_stuff.incoming_dir, "\\");
- res++;
- }
-
- if ((stricmp(p, "domain") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.my_domain, v);
- res++;
- }
-
- if ((stricmp(p, "tempdir") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.temp_name, v);
- if (my_stuff.temp_name[strlen(my_stuff.temp_name)-1] == '\\')
- my_stuff.temp_name[strlen(my_stuff.temp_name)-1] = '\0';
- res++;
- }
-
- if ((stricmp(p, "aliasfile") == 0) && (v != NULL)) {
- strcpy(my_stuff.alias_file, v);
- /* not a required item */
- }
-
- if ((stricmp(p, "userid") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.user, v);
- res++;
- }
-
- if ((stricmp(p, "Signature") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.signature, v);
- res++;
- }
-
- if ((stricmp(p, "name") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.my_name, v);
- v = strtok(NULL, " \t=\r\n");
- while (v != NULL) {
- (void) strcat(my_stuff.my_name, " ");
- (void) strcat(my_stuff.my_name, v);
- v = strtok(NULL, " \t=\r\n");
- }
- if (strpbrk(my_stuff.my_name, "()<>@.;:\\\".[]") != NULL) {
- strcpy(buf2, my_stuff.my_name);
- strcpy(my_stuff.my_name, "\"");
- strcat(my_stuff.my_name, buf2);
- strcat(my_stuff.my_name, "\"");
- }
- res++;
- }
-
- if ((stricmp(p, "Organization") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.my_organisation, v);
- v = strtok(NULL, " \t=\r\n");
- while (v != NULL) {
- (void) strcat(my_stuff.my_organisation, " ");
- (void) strcat(my_stuff.my_organisation, v);
- v = strtok(NULL, " \t=\r\n");
- }
- /* Organisation no longer compulsory */
- }
-
- if ((stricmp(p, "Replyto") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.replyuser, v);
- v = strtok(NULL, " =\r\n");
- while (v != NULL) {
- (void) strcat(my_stuff.replyuser, " ");
- (void) strcat(my_stuff.replyuser, v);
- v = strtok(NULL, " =\r\n");
- }
- } /* not a required item for DIS. Don't bump res */
-
- if ((stricmp(p, "Editor") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.editor, v);
- res++;
- v = strtok(NULL, " \t=\r\n");
- while (v != NULL) {
- (void) strcat(my_stuff.editor, " ");
- (void) strcat(my_stuff.editor, v);
- v = strtok(NULL, " \t=\r\n");
- }
- strlwr(my_stuff.editor);
-
- }
-
- if ((stricmp(p, "Editline") == 0) & (v != NULL)) {
- (void) strcpy(my_stuff.edit_line, v);
- v = strtok(NULL, " \r\n");
- while (v != NULL) {
- strcat(my_stuff.edit_line, " ");
- strcat(my_stuff.edit_line, v);
- v = strtok(NULL, " \r\n");
- }
- }
-
- if ((stricmp(p, "Home") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.home, v);
- if (my_stuff.home[strlen(my_stuff.home) - 1] != '\\')
- (void) strcat(my_stuff.home, "\\");
-
- res++;
- }
-
- if ((stricmp(p, "mailqueue") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.spooldir, v);
- if (my_stuff.spooldir[strlen(my_stuff.spooldir) - 1] != '\\')
- (void) strcat(my_stuff.spooldir, "\\");
-
- res++;
- }
-
- if ((stricmp(p, "mailuser") == 0) && (v != NULL)) {
- if (v != NULL) {
- (void) strcpy(my_stuff.mailuser, v);
- if (strlen(my_stuff.mailuser) > 8)
- my_stuff.mailuser[8] = '\0';
- i = strlen(my_stuff.mailuser) - 1;
- if (my_stuff.mailuser[i] == '.')
- my_stuff.mailuser[i] = '\0';
- }
- else
- strcpy(my_stuff.mailuser, "none");
- /* Mailuser is not a required item to maintain compatibility */
- }
-
- if ((stricmp(p, "maillog") == 0) && (v != NULL)) {
- if (v != NULL) {
- (void) strcpy(my_stuff.maillog, v);
- if (strlen(my_stuff.maillog) > 8)
- my_stuff.maillog[8] = '\0';
- i = strlen(my_stuff.maillog) - 1;
- if (my_stuff.maillog[i] == '.')
- my_stuff.maillog[i] = '\0';
- }
- else
- strcpy(my_stuff.maillog, "none");
- /* Maillog is not a required item to maintain compatibility */
- }
-
- if ((stricmp(p, "extracts") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.extruser, v);
- if (strlen(my_stuff.extruser) > 8)
- my_stuff.extruser[8] = '\0';
- i = strlen(my_stuff.extruser) - 1;
- if (my_stuff.extruser[i] == '.')
- my_stuff.extruser[i] = '\0';
- /* Extracts is not a required item to maintain compatibility */
- }
-
- if ((stricmp(p, "quotemark") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.quotemark, v);
- q = my_stuff.quotemark;
- for(;*q != '\0';q++)
- if (*q == '_')
- *q = ' ';
- /* Quotemark not a required item, so leave 'res' alone */
- }
-
- if ((stricmp(p, "biosvideo") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.directvideo = 1;
- else if (stricmp(v, "2") == 0)
- my_stuff.directvideo = 2;
- else
- my_stuff.directvideo = 0;
- /* biosvideo not a required item, so leave 'res' alone */
- }
-
- if ((stricmp(p, "matchlength") == 0) && (v != NULL)) {
- my_stuff.match_len = atoi(v);
- if (my_stuff.match_len > 128)
- my_stuff.match_len = 128;
- if (my_stuff.match_len < -1)
- my_stuff.match_len = -1;
- /* matchlength is not a required item. */
- }
-
- if ((stricmp(p, "exitconfirm") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.exitconfirm = 1;
- else if (stricmp(v, "2") == 0)
- my_stuff.exitconfirm = 2;
- else
- my_stuff.exitconfirm = 0;
- /* exitconfirm not a required item, so leave 'res' alone */
- }
-
- if ((stricmp(p, "expert") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.expert = FALSE;
- else
- my_stuff.expert = TRUE;
- /* expert not a required item, so leave 'res' alone */
- }
-
- if ((stricmp(p, "TAB") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.tab_action = FALSE;
- else
- my_stuff.tab_action = TRUE;
- }
-
- if ((stricmp(p, "HEADERS") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.header_quote = FALSE;
- else
- my_stuff.header_quote = TRUE;
- }
-
- if ((stricmp(p, "FOOTERS") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.footer_quote = FALSE;
- else
- my_stuff.footer_quote = TRUE;
- }
-
- if ((stricmp(p, "UNREAD") == 0) && (v != NULL)) {
- if (stricmp(v, "0") == 0
- || stricmp(v, "false") == 0
- || stricmp(v, "no") == 0
- || stricmp(v, "off") == 0)
- my_stuff.show_unread = FALSE;
- else
- my_stuff.show_unread = TRUE;
- }
-
- if ((stricmp(p, "post") == 0) && (v != NULL)) {
- if (strnicmp(v, "local", 5) == 0)
- my_stuff.localpost = 1;
- else
- my_stuff.localpost = 0;
- if (stricmp(v, "local/read") == 0)
- my_stuff.localread = 1;
- else
- my_stuff.localread = 0;
- /* post is not a required item */
- }
-
- if ((stricmp(p, "newsid") == 0) && (v != NULL)) {
- (void) strcpy(my_stuff.mail_id, v);
- /* newsid is not a required item */
- }
- } /* if (*p != '#') */
- } /* if (p != NULL) */
- } /* while (fgets (buf, 255, tmp)) */
-
- fclose(tmp);
- strcpy(my_stuff.mail_dir, my_stuff.spooldir);
- p = strrchr(my_stuff.mail_dir, '\\');
- if (p != NULL) {
- *p = '\0';
- p = strrchr(my_stuff.mail_dir, '\\');
- *(p + 1) = '\0';
- }
- strcpy(my_stuff.nntp_dir, my_stuff.mail_dir);
- strcat(my_stuff.mail_dir, "mail\\");
- strcat(my_stuff.nntp_dir, "news\\");
- } /* if ((tmp = fopen (buf, "rt")) != NULL) */
- else {
- (void) fprintf(stderr, "Cannot open %s\n", buf);
- }
-
- return (res == 11);
- } /* int load_stuff (void) */
-
-
- /*--------------------------- open newsgroup ------------------------*/
- FILE *open_out_file(char *ng, int *junk_flag)
- {
-
- /*
- * This routine creates a filename from the newsgroup name.
- * The active file counters are updated.
- */
-
- ACTIVE *gp;
- char *fn;
- FILE *tmp;
-
- gp = find_news_group(ng, junk_flag);
- fn = make_news_group_name(gp->group);
-
- (gp->hi_num)++;
- update_active_entry(gp);
-
- if ((tmp = fopen(fn, "r+b")) == NULL) {
- fprintf(stderr, "active: cannot open text file %s\n", fn);
- exit(1);
- }
- fseek(tmp, 0, SEEK_END);
-
- return (tmp);
-
- }
-
-
- /*--------------------------- open index ------------------------*/
- FILE *open_index_file(char *ng)
- {
-
- /*
- * This routine open the index file for the newsgroup
- */
-
- ACTIVE *gp;
- char fnx[256], *fn;
- FILE *tmp;
- int junk_flag;
-
- /* printf("news: ng found = %s\n", ng); */
-
- gp = find_news_group(ng, &junk_flag);
- fn = make_news_group_name(gp->group);
- sprintf(fnx, "%s.IDX", fn);
-
- if ((tmp = fopen(fnx, "r+b")) == NULL) {
- fprintf(stderr, "active: cannot open index file %s\n", fn);
- exit(1);
- }
- fseek(tmp, 0, SEEK_END);
-
- return (tmp);
-
- }
-
- /*------------------------ Load suspend list --------------------------------*/
- SUSPEND *load_suspend(void)
- {
- char fn[80], buf[256];
- FILE *suspend_file;
- SUSPEND *suspend_head, *sus;
-
- /* open the file */
- strcpy(fn, my_stuff.news_dir);
- strcat(fn, "suspend");
- if ((suspend_file = fopen(fn, "r+b")) == NULL) {
- return NULL;
- }
- suspend_head = sus = NULL;
- /* read and store */
- while (fgets(buf, 80, suspend_file) != NULL) {
-
- /* exit on ^Z on column 1 */
- if (buf[0] == '\x1A')
- break;
- while ((buf[strlen(buf)-1] == '\n') || (buf[strlen(buf)-1] == '\r'))
- buf[strlen(buf)-1] = '\0';
-
- if (strlen(buf) > 0) {
- if (sus == NULL) {
- sus = (SUSPEND*)malloc(sizeof(SUSPEND));
- strcpy(sus->group, buf);
- sus->next = NULL;
- suspend_head = sus;
- }
- else {
- sus->next = (SUSPEND*)malloc(sizeof(SUSPEND));
- sus = sus->next;
- sus->next = NULL;
- strcpy(sus->group, buf);
- }
- }
- }
- return suspend_head;
- }
-
- /*------------------------- Add suspend info -------------------------------*/
- void add_suspend(ACTIVE *head)
- {
- SUSPEND *suspend_head, *sus;
- ACTIVE *act;
-
- suspend_head = load_suspend();
- act = head;
- if (suspend_head == NULL)
- return;
-
- while (act != NULL) {
- sus = suspend_head;
- while (sus != NULL) {
- if (stricmp(sus->group, act->group) == 0)
- act->suspend = TRUE;
- sus = sus->next;
- }
- act = act->next;
- }
-
- free_suspend(suspend_head);
- }
-
- /*------------------------- Free suspend structure -------------------------*/
- void free_suspend(SUSPEND *suspend_head)
- {
- SUSPEND *sus, *sus2;
-
- sus = suspend_head;
-
- while (sus != NULL) {
- sus2 = sus->next;
- free(sus);
- sus = sus2;
- }
- }
-
- /*------------------------- post sequence number ----------------------------*/
- int post_sequence(void)
- {
-
- /*
- * Get the sequnce number from the seq file if it exists
- * - if not create it
- */
-
- FILE *seq_file;
- char fn[256];
- int seq;
-
- strcpy(fn, my_stuff.news_dir);
- strcat(fn, "nseq");
-
- if (mlock(my_stuff.news_dir, "nseq", "Active") != 0)
- return -1;
- if ((seq_file = fopen(fn, "r+")) != NULL) {
- fscanf(seq_file, "%d", &seq);
- seq++;
- rewind(seq_file);
- }
- else {
- seq = 0;
- seq_file = fopen(fn, "wt");
- }
-
- fprintf(seq_file, "%d", seq);
-
- fclose(seq_file);
- rmlock(my_stuff.news_dir, "nseq", "Active");
- return (seq);
- }
-
-
- /*-------------------------------- safeish malloc --------------------------*/
- #if defined (malloc)
- #undef malloc
- #endif
-
- void *xmalloc(size_t size)
- {
- void *p;
-
- if ((p = malloc(size)) == NULL) {
- gotoxy(1, 25);
- fprintf(stderr, "\n\nSORRY - OUT OF MEMORY \n");
- exit(1);
- }
- return (p);
- }
-